﻿// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
using System;
using System.Runtime.Serialization;
//using System.Runtime.Serialization;
//using System.Collections.Generic;

namespace Microsoft.Xrm.Sdk
{
	public interface IExecutionContext
	{
		/// <summary>
		/// Mode of the processing.
		/// </summary>
		int Mode
		{
			get;
		}

		/// <summary>
		/// Indicates the plug-in's isolation mode.
		/// </summary>
		int IsolationMode
		{
			get;
		}

		int Depth
		{
			get; 
		}

		/// <summary>
		/// Name of the message being processed.
		/// </summary>
		string MessageName
		{
			get;
		}

		/// <summary>
		/// Name of the primary entity that is associated with the message.
		/// </summary>
		string PrimaryEntityName
		{
			get;
		}

		/// <summary>
		/// RequestId if specified by SDK client
		/// </summary>
		Guid? RequestId
		{
			get;
		}

		/// <summary>
		/// Name of the secondary entity that is associated with the message.
		/// </summary>
		string SecondaryEntityName
		{
			get;
		}

		/// <summary>
		/// Input parameters from the caller.
		/// </summary>
		ParameterCollection InputParameters
		{
			get;
		}

		/// <summary>
		/// Output parameters to be returned back to caller.
		/// </summary>
		ParameterCollection OutputParameters
		{
			get;
		}

		/// <summary>
		/// Temporary parameters passing between plug-ins.
		/// </summary>
		ParameterCollection SharedVariables
		{
			get;
		}

		/// <summary>
		/// Id of user that plug-in is executing as.
		/// </summary>
		Guid UserId
		{
			get;
		}

		/// <summary>
		/// Id of user that initiates web service.
		/// </summary>
		Guid InitiatingUserId
		{
			get;
		}

		/// <summary>
		/// Id of business unit that user that plug-in is executing as.
		/// </summary>
		Guid BusinessUnitId
		{
			get;
		}

		/// <summary>
		/// Id of the organization that the plug-in is executing in.
		/// </summary>
		Guid OrganizationId
		{
			get;
		}

		/// <summary>
		/// Unique name of organization that plug-in is executing in.
		/// </summary>
		string OrganizationName
		{
			get;
		}

		/// <summary>
		/// Id of the Entity that trigged the extension.
		/// </summary>
		Guid PrimaryEntityId
		{
			get;
		}

		/// <summary>
		/// Contains a copy of the Entity prior to the platform taking action on it.
		/// </summary>
		EntityImageCollection PreEntityImages
		{
			get;
		}

		/// <summary>
		/// Contains a copy of the Entity after the platform has taken action on it.
		/// </summary>
		EntityImageCollection PostEntityImages
		{
			get;
		}

		/// <summary>
		/// Either the Workflow record representing the Activation or the SdkMessageProcessingStep the is currently executing
		/// </summary>
		EntityReference OwningExtension
		{
			get;
		}

		/// <summary>
		/// Id to correlate between multiple requests.
		/// </summary>
		Guid CorrelationId
		{
			get;
		}

		/// <summary>
		/// Indicates whether the plugin is running in offline mode
		/// </summary>
		bool IsExecutingOffline
		{
			get;
		}

		/// <summary>
		/// Indicates whether the plugin is running during offline playback
		/// </summary>
		bool IsOfflinePlayback
		{
			get;
		}

		/// <summary> 
		/// Indicates whether the context is executing in transaction or not
		/// </summary>
		bool IsInTransaction
		{
			get;
		}

		/// <summary>
		/// The AsyncOperationId that is executing the current extension.
		/// </summary>
		Guid OperationId
		{
			get; 
		}

		/// <summary>
		/// The time that the AsyncOperation was created on.
		/// </summary>
		DateTime OperationCreatedOn
		{
			get;
		}
	}

	public interface IPluginExecutionContext : IExecutionContext
	{
		/// <summary>
		/// Stage of the processing.
		/// </summary>
		int Stage
		{
			get;
		}

		IPluginExecutionContext ParentContext
		{
			get; 
		}
	}
}
